package handle

import (
	"gitee.com/crack007/goose/core/web"
	"gitee.com/crack007/udp-penetrate/src/api/config"
	"gitee.com/crack007/udp-penetrate/src/api/router"
	"gitee.com/crack007/udp-penetrate/src/api/service"
	"gitee.com/crack007/udp-penetrate/src/common/dto"
	"gitee.com/crack007/udp-penetrate/src/common/protocol"
)

type clientApiHandle struct {
	web.DefaultHttpServerHandle
	Uid uint32
}

func NewClientApiHandle() *clientApiHandle {
	return &clientApiHandle{}
}

func (h *clientApiHandle) OnInitRouter() {
	router.ClientApi(h.GetHttpServer())
}

func (h *clientApiHandle) OnInitConfig() {
	config.Init(h.GetHttpServer().GetConfigPath())
}

func (h *clientApiHandle) OnInitService() {
	protocol.RegisterProtocol(protocol.NewHandshakeRespProtocol())
	protocol.RegisterProtocol(protocol.NewClientHandshakeReqProtocol())
	protocol.RegisterProtocol(protocol.NewCtoCHandshakeReqProtocol())
	protocol.RegisterProtocol(protocol.NewHeartbeatProtocol())
	protocol.RegisterProtocol(protocol.NewMessageProtocol())

}

func (h *clientApiHandle) OnBeforeRun() {
	service.ClientService.CheckIn(&dto.UserDto{Uid: h.Uid})
}
